package com.hsj.service.imp;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hsj.dao.BookDao;
import com.hsj.domain.Book;
import com.hsj.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {


    @Autowired
    BookDao bookDao;

    @Override
    public Boolean save(Book book) {
        return bookDao.insert(book) > 0 ;
    }

    @Override
    public Boolean update(Book book) {
        return bookDao.updateById(book) >0;
    }

    @Override
    public Boolean delete(Integer id) {
        return bookDao.deleteById(id) >0;
    }

    @Override
    public Book getById(Integer id) {
        return bookDao.getBookById(id) ;
    }

    @Override
    public List<Book> getAll() {
        return bookDao.selectList(null);
    }

    @Override
    public Page<Book> getPage(int currentPage,int pageSize) {
        Page page = new Page(currentPage, pageSize);   //创建一个page对象 放入分页查询中
        return bookDao.selectPage(page,null);  //分页查询
    }
}
